import time
from selenium import webdriver
from bs4 import BeautifulSoup

# 打开浏览器
browser = webdriver.Chrome()
# browser = webdriver.Edge()
# 设置浏览器位置
# 打开网址
browser.get('https://mail.qq.com/')
# 因为qq登陆窗口是一个iframe，所以先切换到iframe
login_frame = browser.find_element_by_id('login_frame')
# 切换到login_frame
# browser.switch_to_frame(login_frame) 旧版写法
browser.switch_to.frame(login_frame)
# 点击切换成账号密码登陆
browser.find_element_by_id('switcher_plogin').click()
# 写入账号
browser.find_element_by_id('u').send_keys('741510728')
browser.find_element_by_id('p').send_keys('***')
browser.find_element_by_id('login_button').click()

# browser.switch_to.frame('mainFrame')
html = browser.page_source
soup = BeautifulSoup(html,'html.parser')
try:
    params = soup.select('.folder_1')[0].text.strip()
    print("有"+str(params)+"封新邮件！")
except IndexError as e:
    print("没有新邮件！")
# browser.quit()

